// 定义属性相关的信息
import request from "@/utils/request";
import type { getCategoryType, attrType, dataArr, generalInfo } from "./type";
// 枚举接口
enum API {
    // 一级
    CF_URL = "/admin/product/getCategory1",
    // 二级
    CS_URL = "/admin/product/getCategory2/",
    // 三级
    CT_URL = "/admin/product/getCategory3/",
    // 获取商品属性
    ATTR_URL = "/admin/product/attrInfoList/",
    // 新增和修改商品属性值
    ADD_UPDATE_URL = "/admin/product/saveAttrInfo",
    // 删除商品属性
    DELETE_URL="/admin/product/deleteAttr/"
}

export const getCategory1 = () => request.get<any, getCategoryType>(API.CF_URL);

export const getCategory2 = (category1Id: number | string) =>
    request.get<any, getCategoryType>(API.CS_URL + category1Id);

export const getCategory3 = (category2Id: number | string | undefined) =>
    request.get<any, getCategoryType>(API.CT_URL + category2Id);

export const getAttr = (
    category1Id: number | string,
    category2Id: number | string | undefined,
    category3Id: number | string | undefined
) =>
    request.get<any, attrType>(
        API.ATTR_URL + `${category1Id}/${category2Id}/${category3Id}`
    );

export const addAndUpdate = (data: dataArr) => request.post<any, generalInfo>(API.ADD_UPDATE_URL, data);

export const deleteAttr = (attrId:number)=>request.delete<any,any>(API.DELETE_URL+attrId)
